package com.example.demo.ImgTest;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.imagesearch.v2.region.ImageSearchRegion;
import com.huaweicloud.sdk.imagesearch.v2.*;
import com.huaweicloud.sdk.imagesearch.v2.model.*;

/**
 * 图像搜索
 *
 * @author FF998
 */
public class HuaWeiSearchA {
    public static void main(String[] args) {
        String ak = "D4V7FPPVAS2W3YRJSPYF";
        String sk = "dKmJyVJtxe4zn3mfvVVgTpSqtQB36MADe8H4reSz";

        ICredential auth = new BasicCredentials()
                .withAk(ak)
                .withSk(sk);

        ImageSearchClient client = ImageSearchClient.newBuilder()
                .withCredential(auth)
                .withRegion(ImageSearchRegion.valueOf("cn-north-4"))
                .build();
        RunSearchRequest request = new RunSearchRequest();
        SearchParam body = new SearchParam();
        request.withBody(body);
        try {
            RunSearchResponse response = client.runSearch(request);
            System.out.println(response.toString());
        } catch (ConnectionException | RequestTimeoutException e) {
            e.printStackTrace();
        } catch (ServiceResponseException e) {
            e.printStackTrace();
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getRequestId());
            System.out.println(e.getErrorCode());
            System.out.println(e.getErrorMsg());
        }
    }
}
